// const BASEURL = 'https://only.java.heiwangke.net/material-check-api'; //线上
const BASEURL = 'https://bsc-smt.bestherb0513.cn/material-check-api'; //线上

const request = (config) => {
	let header = {
		"Content-Type": config.contentType || "application/json;charset=utf-8",
	}
	return new Promise((resove, reject) => {
		uni.request({
			url: BASEURL + config.url,
			data: config.data || '',
			header: {
				'Authorization': 'Bearer ' + uni.getStorageSync('token'),
				'token': uni.getStorageSync('token')
			},
			method: config.method,
			dataType: "json",
			success: (res) => {
				const {
					data
				} = res
				const {
					code,
					result
				} = data
				switch (code) {
					case 200:
						resove(res.data)
						break
					case 401:
						uni.reLaunch({
							url: '/pages/login/login'
						})
						break
					default:
						resove(res.data)
						// uni.showToast({
						// 	title: data.msg,
						// 	duration: 2000,
						// 	mask: false,
						// 	icon: "none"
						// })
				}
			},
			fail: (error) => {
				uni.showToast({
					title: "请求错误",
					duration: 1500,
					mask: false,
					icon: "none"
				});
				reject(error)
			},
			complete: () => {
				setTimeout(() => {
					uni.hideLoading()
				}, 1500)
			}
		})
	})
}
export default request